/*
	Anonymous Image Board Image Downloader - program for downloading pictures from AIB
	Copyright (C) 2011-2012 Metallhead <Metallhead@megabox.ru>

	HomePage:    http://code.google.com/p/aibid/

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QNetworkReply>
#include <QVector>
#include "downloads.h"
#include <QSystemTrayIcon>
#include <QStandardItemModel>
#include "progresslist.h"
#include "ui_mainwindow.h"
#include "adddialog.h"
#include "settingsdialog.h"
#include "feedback.h"
#include "threadinfo.h"
#include "common.h"
#include "xmleditor.h"
#include <QClipboard>
#include <QDir>

namespace Ui {
	class MainWindow;
}

class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	explicit MainWindow(QString applicationName, QWidget *parent = 0);
	~MainWindow();

private:
	Ui::MainWindow *ui;
	//QVector<downloading*> threads;
	QVector<downloads*> threads;
	QSystemTrayIcon * tray;

	QStandardItemModel model;

	//QStandardItemModel model(0, 3);
	addDialog *add;
	settingsDialog * set;
	FeedBack * fb;
	threadInfo * info;
	XmlEditor xE;
	progressList delegate;
	QString appName;
	double version;
//	double versionToDownload;
	//bool onlyRemove;
	//int filesDownloaded, filesNeedToDownload;
#ifndef Q_OS_LINUX
	void checkNewVersion();
#endif

	void addThread(QString site, QString path, int updateTime, int threadsAmount, QDateTime additionTime, bool loading, imageTypes alowedTypes);
	void updateThread(int index, QNetworkReply * reply);
	void deleteThread(int row);
	void resumeThread(int index);
	void stopThread(int index);

	void closeEvent(QCloseEvent *q);
	void resizeEvent(QResizeEvent *q);


	void loadThreads(QSettings & settings);
	void saveAllThreadsToRegistry(QSettings & settings);
	void loadColumnsSizes();
	QString downloadAddress;

private slots:
	void on_resumeThread_clicked();
	void on_stopThread_clicked();
	void on_openFolder_clicked();
	void on_deleteThread_clicked();
	void on_addThread_clicked();
	void openSettings_clicked();
	void showHide(QSystemTrayIcon::ActivationReason);
	void updateProgressBar(int index);
	void stopAllDownloads();
	void resumeAllDownloads();
	void deleteAllDownloads();
	void exitProgram();
	void versionInfoDownloadFinished(QNetworkReply * reply);
	void saveAllThreadsToRegistry();
	void deleteAllThreadsFromRegistry();
	void on_actionExit_triggered();
	void on_actionFeedback_triggered();
	void on_tableView_doubleClicked(const QModelIndex &index);
	void on_tableView_customContextMenuRequested(const QPoint &pos);
	void copyUrlToClipboard();
	void on_actionOpenDetectorsEditor_triggered();
	void columnSizeChanged(int columnIndex, int oldSize, int newSize);
	void openThreadInBrowser();
#ifdef Q_OS_MAC
	void downloadMacFile(QNetworkReply *);
#endif
	void on_actionExport_list_triggered();
	void on_actionImport_list_triggered();
};

#endif // MAINWINDOW_H
